<script>
  /*
声明一个Car的class
有静态属性
- MaxSpeed最大速度120
- StatusRunning = '运行中'
- StatusStop = '熄火'
有属性
- speed 速度（私有）
- brand 品牌
- color 颜色
- status状态（默认状态熄火）（私有）
有方法
- start() 设置状态为运行中
- stop() 设置状态为熄火
- accelerate()加速，每运行一次提速10，只有运行中的才能提速，不能超过最大速度
- slowdown()减速，每运行一次减速10，只有运行中的才能减速，不能低于0
- brake() 刹车，速度重置为0
- setColor() 设置颜色
- toString() 返回 "x颜色y品牌的车，状态：？？，速度：？？"
*/
  class Car {
    static MaxSpeed = 120;
    static StatusRunning = "运行中";
    static StatusStop = "熄火";

    #speed = 0;
    #status = "熄火";

    constructor(brand, color) {
      this.brand = brand;
      this.color = color;
    }

    start() {
      //this.#status = '运行中'
      this.#status = Car.StatusRunning;
    }
    stop() {
      //this.#status ='熄火'
      if (this.#speed == 0) {
        this.#status = Car.StatusStop;
      }
    }
    accelerate() {
      if (this.#status == Car.StatusRunning) {
        const s = this.#speed + 10;
        this.#speed = s > Car.MaxSpeed ? Car.MaxSpeed : s;
      }
    }
    slowdown() {
      if (this.#status == Car.StatusRunning) {
        const s = this.#speed - 10;
        this.#speed = s < 0 ? 0 : s;
      }
    }
    brake() {
      this.#speed = 0;
    }
    toString() {
      return `${this.color}${this.brand}品牌的车,状态:${this.#status},速度:${
        this.#speed
      }`;
    }
  }

  const car = new Car("布加迪威龙", "白色");
  car.accelerate();
  console.log(car.toString());
  car.start();
  car.accelerate();
  car.accelerate();
  car.accelerate();
  car.accelerate();
  console.log(car.toString());
</script>
